﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ChatData
{
    /// <summary>
    /// Store usernames and passwords. This object is able to be written to disk.
    /// </summary>
    public class UserStore<T> : ActiveUserStore<T> where T : IStoreRecord, new()
    {
        public UserStore()
        {

        }
        public bool Login(string user, string password)
        {
            return thedic[user].Password== password;
        }
        public string getPassword(string user)
        {
            return thedic[user].Password;
        }
        public bool Contains(string user)
        {
            return thedic.ContainsKey(user);
        }
        public void AddNewUser(T user)
        {
            try
            {
                thedic.Add(user.Username, user);
            }
            catch (ArgumentException e)
            {
                throw new InvalidOperationException("Username is already taken");
            }
        }
        public void RemoveUser(string user)
        {
            try
            {
                thedic.Remove(user);
            }
            catch (ArgumentNullException e)
            {
                throw new InvalidOperationException();
            }
        }
    }
}
